package com.ziytek.web.citizen.util;


/**
 * @author fengh
 */
public class TokenUtils {
    private static SecureKey secureKey;

    public static String getToken(String userId, String phone) {
        if (StringUtil.isEmpty(userId) || StringUtil.isEmpty(phone)) {
            return null;
        }
        return AccessToken.encryptAccessToken(getAuthorizeKey(), userId, phone);
    }

    public static AccessToken getEmptyToken() {
        return AccessToken.encryptAndGetAccessToken(getAuthorizeKey(), "", "");
    }

    public static AccessToken getAccessToken(String userId, String phone) {
        return AccessToken.decryptAccessToken(getAuthorizeKey(), getToken(userId, phone));
    }

    public static AccessToken getAccessToken(String token) {
        if (StringUtil.isEmpty(token)) {
            return null;
        }
        return AccessToken.decryptAccessToken(getAuthorizeKey(), token);
    }

    public static SecureKey getAuthorizeKey() {
        if (secureKey == null) {
            secureKey = new AESSecureKey("266029887c7c6cb0");
        }
        return secureKey;
    }

    public static String getAuthorizeKeyStr() {
        return "266029887c7c6cb0";
    }
}
